package ooday04;

import java.util.concurrent.Callable;

public class Test {
    public static void main(String[] args) {


        Animal[] animals=new Animal[5];
        animals[0]=new Dog("小黑",3,"黑");
        animals[1]=new Dog("小白",2,"白");
        animals[2]=new Chick("小花",4,"花");
        animals[3]=new Fish("小鲤鱼",2,"金");
        animals[4]=new Fish("小鲶鱼",1,"黑");
        for (int i=0;i<animals.length;i++){
            animals[i].drink();
            animals[i].eat();

            if (animals[i] instanceof Dog){
                Dog dog= (Dog)animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Swim){
                Swim swim=(Swim) animals[i];
                swim.swim();
            }
        }










        /*
        Master master=new Master();
        Dog dog =new Dog("小黑", 3, "黑");
       Chick chick=new Chick("小刘", 1, "粉");
       Fish fish=new Fish("小青鱼",1,"青");
       master.feed(dog);//在传参的同时，系统自动做了向上造型
       master.feed(chick);
       master.feed(fish);*/







       /* Animal[] animals=new Animal[5];
        animals[0]=new Dog("小黑", 3, "黑");
        animals[1]=new Dog("小白", 2, "白");
        animals[2]=new Chick("坤坤", 2, "黑");
        animals[3]=new Fish ("小鲤鱼", 4, "金");
        animals[4]=new Fish("小青鱼",1,"青");
        for (int i = 0; i < animals.length; i++) {//遍历所有动物
            System.out.println(animals[i].name);
            animals[i].drink();
            animals[i].eat();


            if(animals[i] instanceof Dog){
                Dog dog=(Dog) animals[i];
                dog.lookHome();
                dog.swim();
            }
            if(animals[i] instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Swim){
                Swim s=(Swim) animals[i];
                s.swim();
            }

        }*/





       /* Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 3, "黑");
        dogs[1] = new Dog("小白", 2, "白");
        dogs[2] = new Dog("小刘", 1, "粉");
        for (int i = 0; i < dogs.length; i++) {
            dogs[i].drink();
            dogs[i].eat();
            dogs[i].lookHome();
            dogs[i].swim();
        }
        System.out.println();





        Chick[] chicks = new Chick[3];
        chicks[0] = new Chick("思思", 4, "黄");
        chicks[1] = new Chick("甜甜", 3, "棕黄");
        chicks[2] = new Chick("坤坤", 2, "黑");
        for (int i=0;i<chicks.length;i++ ) {
            chicks[i].drink();
            chicks[i].eat();
            chicks[i].layEggs();

        }
        System.out.println();




        Fish[] fish=new Fish[4];
        fish[0] = new Fish ("小鲤鱼", 4, "金");
        fish[1] = new Fish("小鲶鱼", 3, "灰");
        fish[2] = new Fish("小黑鱼", 2, "黑");
        fish[3]=new Fish("小青鱼",1,"青");
        for (int i=0;i<fish.length;i++){
            fish[i].drink();
            fish[i].eat();
            fish[i].swim();
        }*/
    }
}